﻿using FieldTools.MediaFindOut.Control;
using ImageMagick;
using MediaInfo;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.WindowsAPICodePack.Shell;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Threading;
using File = System.IO.File;
using Timer = System.Timers.Timer;

namespace FieldTools.MediaFindOut
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        #region 初始化
        ILogger<MainWindow> logger = new NullLogger<MainWindow>();
        /// <summary>
        /// 
        /// </summary>
        public MainWindow()
        {
            Init();
            this.DataContext = this;
            InitializeComponent();
            this.Closed += MainWindow_Closed;
        }
        /// <summary>
        /// 界面关闭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainWindow_Closed(object? sender, EventArgs e)
        {
            timer.Stop();
            timer.Dispose();
            processTimer.Stop();
            processTimer.Dispose();
            cpuCounter?.Dispose();
            ramCounter?.Dispose();
        }
        /// <summary>
        /// 获取配置并通过反射设置对象值
        /// </summary>
        /// <param name="obj"></param>
        public static void ConfigToEntity(object obj)
        {
            var configs = ConfigHelper.ReadAllSettings();
            var prs = obj.GetType().GetProperties();
            foreach (var p in prs)
            {
                if (configs.TryGetValue(p.Name, out string? value))
                {
                    p.SetValue(obj, Convert.ChangeType(value, p.GetValue(obj) != null ? p.GetValue(obj).GetType() : typeof(string)));
                }
            }
        }
        /// <summary>
        /// 初始化
        /// </summary>
        private void Init()
        {
            Model = new();
            ConfigToEntity(Model);
            Model.InputPath ??= Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + "\\";
            //OutputPath = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + "\\OutImgs\\";
            TimerInit();
            string name = Process.GetCurrentProcess().ProcessName;
            cpuCounter = new PerformanceCounter("Process", "% Processor Time", name);
            ramCounter = new PerformanceCounter("Process", "Working Set", name);
            //ramCounter = new PerformanceCounter("Process", "Private Bytes", name);
        }
        /// <summary>
        /// 定时器初始化
        /// </summary>
        private void TimerInit()
        {
            timer.Elapsed += new ElapsedEventHandler(TimerExecute);//到达时间的时候执行事件；
            timer.AutoReset = true;//设置是执行一次（false）还是一直执行(true)；
            timer.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件；
            timer.Start(); //启动定时器

            processTimer.Elapsed += new ElapsedEventHandler(ProcessTimerExecute);
            processTimer.AutoReset = true;
            processTimer.Enabled = true;
            processTimer.Start();
        }
        #endregion

        #region 实体
        /// <summary>
        /// CPU计数器
        /// </summary>
        PerformanceCounter? cpuCounter = null;
        /// <summary>
        /// Ram计数器
        /// </summary>
        PerformanceCounter? ramCounter = null;
        /// <summary>
        /// 内存占用
        /// </summary>
        public double MemoryUsage
        {
            get { return (double)GetValue(MemoryUsageProperty); }
            set { SetValue(MemoryUsageProperty, value); }
        }
        /// <summary>
        /// Using a DependencyProperty as the backing store for MemoryUsage.  This enables animation, styling, binding, etc...
        /// </summary>
        public static readonly DependencyProperty MemoryUsageProperty =
            DependencyProperty.Register("MemoryUsage", typeof(double), typeof(MainWindow), new PropertyMetadata(0d));
        /// <summary>
        /// CPU占用
        /// </summary>
        public double CPUUsage
        {
            get { return (double)GetValue(CPUUsageProperty); }
            set { SetValue(CPUUsageProperty, value); }
        }
        /// <summary>
        /// Using a DependencyProperty as the backing store for CPUUsage.  This enables animation, styling, binding, etc...
        /// </summary>
        public static readonly DependencyProperty CPUUsageProperty =
            DependencyProperty.Register("CPUUsage", typeof(double), typeof(MainWindow), new PropertyMetadata(0d));
        const int Interval = 100;
        /// <summary>
        /// 定时器
        /// </summary>
        readonly Timer timer = new(Interval);
        /// <summary>
        /// 获取进程占用信息的定时器
        /// </summary>
        readonly Timer processTimer = new(1000);
        /// <summary>
        /// 花费时间
        /// </summary>
        public string TimeSpent
        {
            get { return (string)GetValue(TimeSpentProperty); }
            set { SetValue(TimeSpentProperty, value); }
        }
        /// <summary>
        /// Using a DependencyProperty as the backing store for TimeSpent.  This enables animation, styling, binding, etc...
        /// </summary>
        public static readonly DependencyProperty TimeSpentProperty =
            DependencyProperty.Register("TimeSpent", typeof(string), typeof(MainWindow), new PropertyMetadata("00:00:00:00:000"));
        private long timeSpentNum;
        /// <summary>
        /// 花费时间，数值
        /// </summary>
        public long TimeSpentNum
        {
            get { return timeSpentNum; }
            set
            {
                timeSpentNum = value;
                TimeSpan timeSpan = TimeSpan.FromMilliseconds(value);
                TimeSpent = $"{timeSpan.Days:00}:{timeSpan.Hours:00}:{timeSpan.Minutes:00}:{timeSpan.Seconds:00}:{timeSpan.Milliseconds:000}";
            }
        }

        private bool isExcute;
        /// <summary>
        /// 是否执行中
        /// </summary>
        public bool IsExcute
        {
            get { return isExcute; }
            set
            {
                isExcute = value;
            }
        }
        /// <summary>
        /// 输出模式
        /// </summary>
        public static List<KeyValuePair<string, int>> OutModes => [
                new("仅预览",0),
                new("导出目录文件",1),
                new("导出文件到目录",2)
            ];
        /// <summary>
        /// 媒体类型
        /// </summary>
        public static List<KeyValuePair<string, int>> MediaTypes =>
            [
                new ("图片",1),
                new ("视频",2),
                new ("其他",3)
            ];
        /// <summary>
        /// 快速路径
        /// </summary>
        public static List<KeyValuePair<string, string>> QuickePaths =>
        [
                new ("图片",Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)+"\\"),
                new ("文档",Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)+"\\"),
                new ("桌面",Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)+"\\"),
                new ("下载",KnownFolders.Downloads.Path+"\\")
            ];
        /// <summary>
        /// 输出日志
        /// </summary>
        public string OutLog
        {
            get { return (string)GetValue(OutLogProperty); }
            set { SetValue(OutLogProperty, value); }
        }
        /// <summary>
        /// Using a DependencyProperty as the backing store for OutLog.  This enables animation, styling, binding, etc...
        /// </summary>
        public static readonly DependencyProperty OutLogProperty =
            DependencyProperty.Register("OutLog", typeof(string), typeof(MainWindow), new PropertyMetadata(""));
        /// <summary>
        /// 数据模型
        /// </summary>
        public MainWindowModel? Model { get; set; }
        /// <summary>
        /// 满足条件的路径
        /// </summary>
        public List<string> FilePaths { get; set; } = [];
        /// <summary>
        /// 所有文件数量
        /// </summary>
        private long FileAllCount { get; set; } = 0;
        #endregion

        #region 事件
        /// <summary>
        /// 定时器执行
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TimerExecute(object? sender, ElapsedEventArgs e)
        {
            //执行时间
            if (IsExcute)
            {
                Dispatcher.Invoke(new Action(() => { TimeSpentNum += Interval; }));
            }
        }
        /// <summary>
        /// 获取当前程序进程信息的定时器执行
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ProcessTimerExecute(object? sender, ElapsedEventArgs e)
        {
            //资源占用
            Dispatcher.Invoke(new Action(() =>
            {
                if (cpuCounter != null && ramCounter != null)
                {
                    CPUUsage = Math.Round(cpuCounter.NextValue() / 100, 2, MidpointRounding.AwayFromZero);
                    MemoryUsage = Math.Round(ramCounter.NextValue() / 1024 / 1024, 2, MidpointRounding.AwayFromZero);
                }
            }));
        }
        /// <summary>
        /// 选择输入路径
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SelectInputPath(object sender, RoutedEventArgs e)
        {
            try
            {
                if (Model != null)
                {
                    Model.InputPath = SelectFolder();
                    AddLineLog("选择了路径:" + Model.InputPath);
                }
            }
            catch (Exception ex)
            {
                MessageManage.Error(ex.Message);
            }
        }
        /// <summary>
        /// 选择输出路径
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SelectOutputPath(object sender, RoutedEventArgs e)
        {
            try
            {
                if (Model != null)
                {
                    Model.OutputPath = SelectFolder() + "\\OutImgs\\";
                    AddLineLog("选择了路径:" + Model.OutputPath);
                }
            }
            catch (Exception ex)
            {
                MessageManage.Error(ex.Message);
            }
        }
        /// <summary>
        /// 清理日志
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ClearLog_Click(object sender, RoutedEventArgs e) => ClearLog();
        /// <summary>
        /// 执行
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void Button_Excute_Click(object sender, RoutedEventArgs e)
        {
            await Excute();
        }
        /// <summary>
        /// 重置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Reset(object sender, RoutedEventArgs e)
        {
            Model = new();
            AddLineLog("已重置输入");
        }
        /// <summary>
        /// 预览
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void Preview(object sender, RoutedEventArgs e)
        {
            if (Model == null) { MessageManage.Error("配置实体错误，请重启"); return; }
            //if (FilePaths.Count == 0) { MessageManage.Warning("预览对象为空，请先执行获取"); return; }
            if (FilePaths == null || FilePaths.Count == 0)
            {
                await Excute();
            }
            if (FilePaths == null || FilePaths.Count == 0) { MessageManage.Warning("执行后为获取到符合要求的对象，请修改输入目录或查询条件"); return; }
            if (Model.MediaType == 1)
            {
                ImgShowWindow window = new(FilePaths);
                window.Show();
            }
            else if (Model.MediaType == 2)
            {
                VLCWindow window = new(FilePaths);
                window.Show();
            }
            else
            {
                FileListShowWindow window = new(FilePaths);
                window.Show();
            }
        }
        /// <summary>
        /// 快速路径选择
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            if (sender is MenuItem menuItem && Model != null)
            {
                Model.InputPath = QuickePaths.Find(x => x.Key == menuItem.Header.ToString()).Value.ToString();
            }
        }
        /// <summary>
        /// 文件浏览器
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void Button_InsideFileExplorer_Click(object sender, RoutedEventArgs e)
        {
            if (FilePaths == null || FilePaths.Count == 0)
            {
                await Excute();
            }
            if (FilePaths == null || FilePaths.Count == 0) { MessageManage.Warning("执行后为获取到符合要求的对象，请修改输入目录或查询条件"); return; }
            if (FilePaths.Count > 0)
            {
                FileListShowWindow window = new(FilePaths);
                window.Show();
            }
        }
        #endregion

        #region 方法
        #region 日志处理
        /// <summary>
        /// 添加一行日志
        /// </summary>
        /// <param name="str"></param>
        public void AddLineLog(string str)
        {
            if (textBoxLog.LineCount > 50) textBoxLog.Clear();
            OutLog += "[" + DateTime.Now.ToString("G") + "]" + str + "\r\n";
            textBoxLog.ScrollToEnd();
        }
        /// <summary>
        /// 清理日志
        /// </summary>
        private void ClearLog()
        {
            OutLog = string.Empty;
            AddLineLog("日志已清理");
        }
        #endregion
        /// <summary>
        /// 执行
        /// </summary>
        /// <returns></returns>
        private async Task Excute()
        {
            if (Model == null) { MessageManage.Error("配置获取错误，请重启"); return; }
            #region 数据合理性判断
            if (string.IsNullOrEmpty(Model.InputPath))
            {
                MessageManage.Warning("输入路径不可为空");
                return;
            }
            if (!Directory.Exists(Model.InputPath))
            {
                MessageManage.Warning("输入路径不存在,请检查");
            }
            if (Model.OutMode != 0 && string.IsNullOrEmpty(Model.OutputPath))
            {
                MessageManage.Warning("输出路径不可为空");
                return;
            }
            if (string.IsNullOrEmpty(Model.SuffixType))
            {
                MessageManage.Warning("后缀类型不可为空");
                return;
            }
            if (Model.WidthMinPx < 0 || Model.HeigthMinPx < 0 || Model.SizeMinKb < 0)
            {
                MessageManage.Warning("尺寸相关数据不可为复数,请检查");
                return;
            }
            if (Model.WidthMaxPx < Model.WidthMinPx || Model.HeigthMaxPx < Model.HeigthMinPx)
            {
                if (Model.WidthMaxPx == 0 && Model.HeigthMaxPx == 0) return;
                MessageManage.Warning("最小像素不可大于最大像素,请检查");
                return;
            }
            if (Model.SizeMaxKb < Model.SizeMinKb && Model.SizeMaxKb != 0)
            {
                MessageManage.Warning("最小大小不可大于最大大小,请检查");
                return;
            }
            #endregion
            try
            {

                //创建输出目录
                var outputPath = Model.OutputPath.EndsWith('\\') ? Model.OutputPath : Model.OutputPath + "\\";
                if (!string.IsNullOrEmpty(Model.OutputPath) && !Directory.Exists(outputPath) && Model.OutMode != 0) Directory.CreateDirectory(outputPath);
                //获取待处理文件路径
                ClearLog();
                IsExcute = true;
                TimeSpentNum = 0;
                AddLineLog("任务执行中……");
                var oldTime = DateTime.UtcNow;
                var tempAction = (DateTime time) =>
                {
                    var ts = time - new DateTime(1970, 1, 1, 0, 0, 0, 0);
                    return Convert.ToInt64(ts.TotalMilliseconds);
                };
                var inputPath = Model.InputPath.EndsWith('\\') ? Model.InputPath : Model.InputPath + "\\";
                FileAllCount = 0;
                await Task.Run(() => { FilePaths = SearchFiles(inputPath, Model.SuffixType, Model); });

                AddLineLog("任务执行完成");
                AddLineLog($"该目录内总文件{FileAllCount}个");
                AddLineLog($"共筛选到符合条件的资源{FilePaths.Count}个");
                IsExcute = false;
                //输出模式
                if (Model.OutMode == 0)
                {

                }
                else if (Model.OutMode == 1)
                {
                    var filePath = Model.OutputPath + "资源路径集合导出" + DateTime.Now.Ticks + ".txt";
                    if (!File.Exists(filePath))
                    {
                        var st = File.Create(filePath);
                        //所有的流使用后记得都要关闭，不然会出现占用的情况
                        st.Close();
                    }
                    var contentStr = "";
                    FilePaths.ForEach(x => { contentStr += x + "\r\n"; });
                    await File.WriteAllTextAsync(filePath, contentStr);
                    AddLineLog($"已完成资源路径集合导出,输出文件为：{filePath}");
                    MessageManage.Success("操作成功，详情请看日志");
                }
                else if (Model.OutMode == 2)
                {
                    foreach (var file in FilePaths)
                    {
                        if (File.Exists(file) && Directory.Exists(Model.OutputPath))
                        {
                            SaveAsFile(file, Model.OutputPath);
                            //AddLineLog(file+"已完成复制");
                        }
                    }
                    AddLineLog($"已完成资源复制导出,输出目录为：{Model.OutputPath}");
                    MessageManage.Success("操作成功，详情请看日志");
                }
                else
                {

                }
                AddLineLog($"共花费时间{tempAction(DateTime.UtcNow) - tempAction(oldTime)}毫秒");
            }
            catch (Exception ex)
            {
                MessageManage.Error(ex.Message);
            }
        }
        /// <summary>
        /// 选择路径
        /// </summary>
        /// <returns></returns>
        public static string SelectFolder()
        {
            using var dialog = new FolderBrowserDialog
            {
                Description = "Select a folder",
                UseDescriptionForTitle = true,
                ShowNewFolderButton = true
            };
            var folderName = Environment.CurrentDirectory;
            var result = dialog.ShowDialog();
            if (result == System.Windows.Forms.DialogResult.OK)
            {
                folderName = dialog.SelectedPath;
                return folderName;
            }
            return folderName;
        }
        /// <summary>
        /// 保存文件，自动重命名
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="outPath"></param>
        /// <exception cref="ArgumentException"></exception>
        /// <exception cref="FileNotFoundException"></exception>
        public static void SaveAsFile(string filePath, string outPath)
        {
            if (string.IsNullOrEmpty(filePath)) throw new ArgumentException($"“{nameof(filePath)}”不能为 null 或空。", nameof(filePath));
            if (string.IsNullOrEmpty(outPath)) throw new ArgumentException($"“{nameof(outPath)}”不能为 null 或空。", nameof(outPath));
            if (!File.Exists(filePath)) throw new FileNotFoundException("需要另存为的文件不存在");

            var fileName = filePath.Split('\\').Last();
            var outFilePath = outPath + "\\" + fileName;
            //重名文件处理，直接加上时间戳
            if (File.Exists(outFilePath))
            {
                var suf = "." + fileName.Split('.').Last();
                outFilePath = outPath + "\\" + fileName.Replace(suf, "_") + DateTime.Now.Ticks + suf;
            }
            File.Copy(filePath, outFilePath);
        }
        /// <summary>
        /// 查询文件
        /// </summary>
        /// <param name="path"></param>
        /// <param name="suffix"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        private List<string> SearchFiles(string path, string suffix, MainWindowModel model)
        {
            model ??= new();
            var filePaths = new List<string>();
            if (!Directory.Exists(path))
            {
                Dispatcher.Invoke(() => { AddLineLog("输入路径不存在"); });
            }

            DirectoryInfo directoryInfo = new(path);
            //检索当前目录
            var files = directoryInfo.GetFiles();
            FileAllCount += files.Length;
            //过滤大小
            files = files.Where(x => x.Length > model.SizeMinKb * 1024 && (model.SizeMaxKb == 0 || x.Length <= model.SizeMaxKb * 1024)).ToArray();
            //过滤后缀
            if (!string.IsNullOrEmpty(suffix))
            {
                Regex regex = new((suffix.Contains('$') ? suffix : suffix + "$").ToLower());//末尾
                files = files.Where(x => regex.IsMatch(x.Name.ToLower())).ToArray();
            }
            var tempAction = (FileInfo file) => { };
            var tempFile = new List<string>();
            //图片过滤尺寸
            if (model.MediaType == 1)
            {
                tempAction = (FileInfo file) =>
                {
                    MagickImageInfo image = new(file.FullName);
                    if (image != null)
                    {
                        if (image.Height > model.HeigthMinPx
                            && (model.HeigthMaxPx == 0 || image.Height <= model.HeigthMaxPx)
                            && image.Width > model.WidthMinPx
                            && (model.WidthMaxPx == 0 || image.Width <= model.WidthMaxPx)
                            )
                        {
                            tempFile.Add(file.FullName);
                            if (model.IsCoursePrint)
                                Dispatcher.Invoke(() => { AddLineLog(file.FullName); });
                        }
                    }
                };
            }
            //视频过滤尺寸
            else if (model.MediaType == 2)
            {
                tempAction = (FileInfo file) =>
                {
                    MediaInfoWrapper video = new(file.FullName, logger);
                    if (video != null)
                    {
                        if (video.Height > model.HeigthMinPx
                            && (model.HeigthMaxPx == 0 || video.Height <= model.HeigthMaxPx)
                            && video.Width > model.WidthMinPx
                            && (model.WidthMaxPx == 0 || video.Width <= model.WidthMaxPx)
                            )
                        {
                            tempFile.Add(file.FullName);
                            if (model.IsCoursePrint)
                                Dispatcher.Invoke(() => { AddLineLog(file.FullName); });
                        }
                    }
                };
            }
            else
            {
                if (Model != null && string.IsNullOrEmpty(Model.SuffixType))
                    AddLineLog("其他类型时，请指定后缀");
            }
            try
            {
                //是否多线程执行
                if (model.IsMultiThreading)
                {
                    Parallel.ForEach(files, file =>
                    {
                        tempAction(file);
                    });
                }
                else
                {
                    foreach (var file in files)
                    {
                        tempAction(file);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageManage.Error(ex.Message);
                //throw;
            }

            filePaths.AddRange(tempFile);
            //检索子目录
            var dirs = directoryInfo.GetDirectories();
            if (dirs.Length > 0 && model.IsIteration)
            {
                //Parallel.ForEach(dirs, dir =>
                //{
                //    filePaths.AddRange(SearchFiles(dir.FullName, suffix, model));
                //});
                foreach (var dir in dirs)
                {
                    filePaths.AddRange(SearchFiles(dir.FullName, suffix, model));
                }
            }

            return filePaths;
        }
        #endregion
    }

    /// <summary>
    /// 数据模型
    /// </summary>
    public class MainWindowModel : INotifyPropertyChanged
    {
        /// <summary>
        /// 属性通知
        /// </summary>
        public event PropertyChangedEventHandler? PropertyChanged;
        /// <summary>
        /// 发起通知
        /// </summary>
        /// <param name="propertyName">属性名</param>
        public void RaisePropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
        /// <summary>
        /// 发起通知的同时保存配置
        /// </summary>
        /// <param name="propertyName"></param>
        /// <param name="value"></param>
        public void RaisePropertyChanged(string propertyName, string value)
        {
            //通知
            RaisePropertyChanged(propertyName);
            //保存配置
            ConfigHelper.AddUpdateAppSettings(propertyName, value);
        }

        private bool isCoursePrint = false;
        /// <summary>
        /// 是否打印过程
        /// </summary>
        public bool IsCoursePrint
        {
            get { return isCoursePrint; }
            set { isCoursePrint = value; RaisePropertyChanged(nameof(IsCoursePrint), value.ToString()); }
        }

        private bool isMultiThreading = false;
        /// <summary>
        /// 是否开启多线程
        /// </summary>
        public bool IsMultiThreading
        {
            get { return isMultiThreading; }
            set
            {
                isMultiThreading = value;
                RaisePropertyChanged(nameof(IsMultiThreading), value.ToString());
            }
        }

        private string inputPath = "";
        /// <summary>
        /// 输入路径
        /// </summary>
        public string InputPath
        {
            get
            {
                return inputPath;
            }
            set
            {
                inputPath = value;
                RaisePropertyChanged(nameof(InputPath), value.ToString());
            }
        }

        private string outputPath = "";
        /// <summary>
        /// 输出路径
        /// </summary>
        public string OutputPath
        {
            get { return outputPath; }
            set { outputPath = value; RaisePropertyChanged(nameof(OutputPath), value.ToString()); }
        }

        private bool isIteration = true;
        /// <summary>
        /// 是否迭代
        /// </summary>
        public bool IsIteration
        {
            get { return isIteration; }
            set { isIteration = value; RaisePropertyChanged(nameof(IsIteration), value.ToString()); }
        }

        private int mediaType = 1;
        /// <summary>
        /// 媒体类型,1图片，2视频
        /// </summary>
        public int MediaType
        {
            get { return mediaType; }
            set
            {
                mediaType = value;
                if (mediaType == 1)
                {
                    SuffixType = "jpg|png|gif|jpeg|svg|bpm";
                }
                else if (mediaType == 2)
                {
                    SuffixType = "mp4|avi|mkv|flv|mov|wmv";
                }
                else
                {
                    SuffixType = "";
                }
                RaisePropertyChanged(nameof(MediaType), value.ToString());
            }
        }

        private string suffixType = "jpg|png";
        /// <summary>
        /// 后缀类型
        /// </summary>
        public string SuffixType
        {
            get { return suffixType; }
            set { suffixType = value; RaisePropertyChanged(nameof(SuffixType), value.ToString()); }
        }

        private int outMode = 0;
        /// <summary>
        /// 输出模式，0仅预览,1导出目录文件,2导出文件到目录
        /// </summary>
        public int OutMode
        {
            get { return outMode; }
            set { outMode = value; RaisePropertyChanged(nameof(OutMode), value.ToString()); }
        }

        private long widthMinPx;
        /// <summary>
        /// 最小宽度(px)
        /// </summary>
        public long WidthMinPx
        {
            get { return widthMinPx; }
            set { widthMinPx = value; RaisePropertyChanged(nameof(WidthMinPx), value.ToString()); }
        }

        private long heigthMinPx;
        /// <summary>
        /// 最小高度(px)
        /// </summary>
        public long HeigthMinPx
        {
            get { return heigthMinPx; }
            set { heigthMinPx = value; RaisePropertyChanged(nameof(HeigthMinPx), value.ToString()); }
        }

        private long widthMaxPx;
        /// <summary>
        /// 最大宽度(px)
        /// </summary>
        public long WidthMaxPx
        {
            get { return widthMaxPx; }
            set { widthMaxPx = value; RaisePropertyChanged(nameof(WidthMaxPx), value.ToString()); }
        }

        private long heigthMaxPx;
        /// <summary>
        /// 最大高度(px)
        /// </summary>
        public long HeigthMaxPx
        {
            get { return heigthMaxPx; }
            set { heigthMaxPx = value; RaisePropertyChanged(nameof(HeigthMaxPx), value.ToString()); }
        }

        private long sizeMinKb;
        /// <summary>
        /// 最小大小(kb)
        /// </summary>
        public long SizeMinKb
        {
            get { return sizeMinKb; }
            set { sizeMinKb = value; RaisePropertyChanged(nameof(SizeMinKb), value.ToString()); }
        }

        private long sizeMaxKb;
        /// <summary>
        /// 最大大小(kb)
        /// </summary>
        public long SizeMaxKb
        {
            get { return sizeMaxKb; }
            set { sizeMaxKb = value; RaisePropertyChanged(nameof(SizeMaxKb), value.ToString()); }
        }
    }
}
